package com.zjw.shortlink.admin.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zjw.shortlink.admin.common.convention.result.Result;
import com.zjw.shortlink.admin.common.convention.result.Results;
import com.zjw.shortlink.admin.remote.ShortLinkActualRemoteService;
import com.zjw.shortlink.admin.remote.dto.req.ShortLinkBatchCreateReqDTO;
import com.zjw.shortlink.admin.remote.dto.req.ShortLinkCreateReqDTO;
import com.zjw.shortlink.admin.remote.dto.req.ShortLinkPageReqDTO;
import com.zjw.shortlink.admin.remote.dto.req.ShortLinkUpdateReqDTO;
import com.zjw.shortlink.admin.remote.dto.resp.ShortLinkBatchCreateRespDTO;
import com.zjw.shortlink.admin.remote.dto.resp.ShortLinkCreateRespDTO;
import com.zjw.shortlink.admin.remote.dto.resp.ShortLinkGroupCountQueryRespDTO;
import com.zjw.shortlink.admin.remote.dto.resp.ShortLinkPageRespDTO;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
public class ShortLinkController {

    private final ShortLinkActualRemoteService shortLinkActualRemoteService;

    @PostMapping("/api/short-link/v1/admin/create")
    public Result<ShortLinkCreateRespDTO> createShortLink(@RequestBody ShortLinkCreateReqDTO requestParams) {
        return shortLinkActualRemoteService.createShortLink(requestParams);
    }

    @PostMapping("/api/short-link/v1/admin/page")
    public Result<IPage<ShortLinkPageRespDTO>> pageShortLink(@RequestBody ShortLinkPageReqDTO requestParams) {
        return shortLinkActualRemoteService.pageShortLink(requestParams);
    }

    @GetMapping("/api/short-link/v1/admin/count")
    public Result<List<ShortLinkGroupCountQueryRespDTO>> listGroupShortLinkCount(@RequestParam("requestParams") List<String> requestParams) {
        return shortLinkActualRemoteService.listGroupShortLinkCount(requestParams);
    }

    @PostMapping("/api/short-link/v1/admin/update")
    public Result<Void> updateShortLink(@RequestBody ShortLinkUpdateReqDTO requestParams) {
        shortLinkActualRemoteService.updateShortLink(requestParams);
        return Results.success();
    }

    @PostMapping("/api/short-link/admin/v1/admin/create/batch")
    public void batchCreateShortLink(@RequestBody ShortLinkBatchCreateReqDTO requestParam, HttpServletResponse response) {
        shortLinkActualRemoteService.batchCreateShortLink(requestParam);
    }
}
